# mitml list
implist <- as.mitml(mymodel)
##################################################
# analysis and pooling
##################################################
# within-cluster (group mean) center level-1 predictors and add cluster-specific group means to the data
for (i in 1:length(implist)) {
implist[[i]] <- gmc(implist[[i]], x = c('psolvepre','hispanic','frlunch'), by = c('school'), FUN = mean, suffix = c('.meanj', '.cwc'), fulldataframe = TRUE)
}
# analysis and pooling
fit <- with(implist, lmer(psolvepst ~ psolvepre.cwc + hispanic.cwc + frlunch.cwc + psolvepre.meanj + hispanic.meanj + frlunch.meanj + condition + (1 | school), REML = T))
# significance tests
estimates <- testEstimates(fit, extra.pars = T)
estimates
confint(estimates)
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","atrisk","stanread")])
# FIML Regression With Categorical Predictors
library(fdir)
library(mdmb)
library(lavaan)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","atrisk","stanread")])
# FIML Regression With Categorical Predictors
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("frlunch","efficacy","mathpost","atrisk","stanread")])
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","atrisk")])
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","atrisk")])
# FIML Moderated Regression
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","readgrp9","stanread7",
"math1","math2","math3","math9","mathgrp9","stanmath7")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread7 ~ 1; read2 ~ 1; read9 ~ 1; read1 ~ 1; lrnprob1 ~ 1; atrisk ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variables
data$read1.cgm <- data$read1 - descriptives$mean["read1"]
data$lrnprob1.cgm <- data$lrnprob1 - descriptives$mean["lrnprob1"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","atrisk")])
# FIML Moderated Regression
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","readgrp9","stanread7",
"math1","math2","math3","math9","mathgrp9","stanmath7")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread7 ~ 1; read2 ~ 1; read9 ~ 1; read1 ~ 1; lrnprob1 ~ 1; atrisk ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variables
data$read1.cgm <- data$read1 - descriptives$mean["read1"]
data$lrnprob1.cgm <- data$lrnprob1 - descriptives$mean["lrnprob1"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","atrisk")])
# FIML Curvilinear Regression
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread ~ 1; atrisk ~ 1; mathpost ~ 1; anxiety ~ 1; frlunch ~ 1; efficacy ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variable
data$anxiety.cgm <- data$anxiety - descriptives$mean["anxiety"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread","mathpost","anxiety.cgm","efficacy")])
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread","mathpost","anxiety.cgm","efficacy","frlunch","atrisk")])
# MCMC Linear Regression
library(fdir)
library(rblimp)
library(mitml)
set_blimp('/Applications/Blimp/blimp-nightly')
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
behaviorachievement <- read.table('behaviorachievement.dat', na.strings = 999)
names(behaviorachievement) <- c('id','male','hispanic','riskgrp','atrisk','behsymp1','lrnprob1',
'read1','read2','read3','read9','read9grp','stanread7',
'math1','math2','math3','math9','math9grp','stanmath7')
##################################################
# fit model with mcmc (ex6.1.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
model = '
focal.model:
read9 ~ read1@beta1 lrnprob1@beta2 behsymp1@beta3;
auxiliary.models:
stanread7 read2  ~ read9 read1 lrnprob1 behsymp1',
waldtest = 'beta1:beta3 = 0',
seed = 90291,
burn = 1000,
iter = 10000)
mymodel@output
##################################################
# fit model and save imputations (ex6.2.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
model = '
focal.model:
read9 ~ read1@beta1 lrnprob1@beta2 behsymp1@beta3;
auxiliary.models:
stanread7 read2  ~ read9 read1 lrnprob1 behsymp1',
waldtest = 'beta1:beta3 = 0',
seed = 90291,
burn = 1000,
iter = 10000,
nimps = 20,
chains = 20)
mymodel@output
# mitml list
implist <- as.mitml(mymodel)
##################################################
# analysis and pooling
##################################################
# analysis and pooling
fit <- with(implist, lm(read9 ~ read1 + lrnprob1 + behsymp1))
# significance tests with barnard & rubin degrees of freedom
estimates <- testEstimates(fit, extra.pars = T, df.com = 134)
estimates
confint(estimates)  # confidence intervals
##################################################
# wald and likelihood ratio (omnibus) tests
##################################################
# wald test that all slopes = 0
null <- with(implist, lm(read9 ~ 1))
testModels(fit, null, df.com = 134, method = 'D1')
mymodel@output
# MCMC Logistic Regression
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
behaviorachievement <- read.table('behaviorachievement.dat', na.strings = 999)
names(behaviorachievement) <- c('id','male','hispanic','riskgrp','atrisk','behsymp1','lrnprob1',
'read1','read2','read3','read9','read9grp','stanread7',
'math1','math2','math3','math9','math9grp','stanmath7')
##################################################
# fit model with mcmc (ex7.1.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
ordinal = 'read9grp ',
model = '
focal.model:
logit(read9grp) ~ read1@beta1 lrnprob1@beta2 behsymp1@beta3;
auxiliary.models:
stanread7 read2  ~ read9grp read1 lrnprob1 behsymp1',
waldtest = 'beta1:beta3 = 0',
seed = 90291,
burn = 1000,
iter = 10000)
mymodel@output
# MCMC Regression With Binary and Ordinal Predictors
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
mathachievement <- read.table('mathachievement.dat', na.strings = 999)
names(mathachievement) <- c('id', 'condition', 'male', 'frlunch', 'atrisk', 'stanread', 'efficacy', 'anxiety', 'mathpre', 'mathpost')
##################################################
# fit model with mcmc (ex8.1.imp)
##################################################
mymodel <- rblimp(
data = mathachievement,
ordinal = 'condition frlunch atrisk efficacy',
fixed = 'condition mathpre',
model = '
focal.model:
mathpost ~ condition@beta1 frlunch@beta2 efficacy@beta3 mathpre@beta4;
auxiliary.models:
stanread atrisk ~ mathpost condition frlunch efficacy mathpre',
waldtest = 'beta1:beta4 = 0',
seed = 90291,
burn = 5000,
iter = 10000)
mymodel@output
# MCMC Regression With Multicategorical Predictor
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
behaviorachievement <- read.table('behaviorachievement.dat', na.strings = 999)
names(behaviorachievement) <- c('id','male','hispanic','riskgrp','atrisk','behsymp1','lrnprob1',
'read1','read2','read3','read9','read9grp','stanread7',
'math1','math2','math3','math9','math9grp','stanmath7')
##################################################
# fit model with mcmc (ex9.1.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
nominal = 'riskgrp',
model = '
focal.model:
read9 ~ read1 lrnprob1 behsymp1 riskgrp;
auxiliary.models:
stanread7 read2   ~ read9 read1 lrnprob1 behsymp1 riskgrp',
seed = 90291,
burn = 2000,
iter = 10000)
mymodel@output
# MCMC Moderated Regression
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
behaviorachievement <- read.table('behaviorachievement.dat', na.strings = 999)
names(behaviorachievement) <- c('id','male','hispanic','riskgrp','atrisk','behsymp1','lrnprob1',
'read1','read2','read3','read9','read9grp','stanread7',
'math1','math2','math3','math9','math9grp','stanmath7')
##################################################
# fit model with mcmc (ex10.1.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
ordinal = 'atrisk',
center = 'read1 lrnprob1 atrisk',
model = '
focal.model:
read9 ~ read1 lrnprob1 read1*lrnprob1 atrisk ;
auxiliary.models:
stanread7 read2  ~ read9 read1 lrnprob1 atrisk',
simple = 'read1 | lrnprob1',
seed = 90291,
burn = 5000,
iter = 10000)
mymodel@output
# MCMC Curvinlinear Regression
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
mathachievement <- read.table('mathachievement.dat', na.strings = 999)
names(mathachievement) <- c('id', 'condition', 'male', 'frlunch', 'atrisk', 'stanread', 'efficacy', 'anxiety', 'mathpre', 'mathpost')
##################################################
# fit model with mcmc (ex11.1.imp)
##################################################
mymodel <- rblimp(
data = mathachievement,
ordinal = 'atrisk frlunch efficacy',
fixed = 'mathpre',
center = 'anxiety',
model = '
focal.model:
mathpost ~ anxiety anxiety^2@beta2 frlunch efficacy mathpre;
auxiliary.models:
stanread atrisk ~ mathpost anxiety frlunch efficacy mathpre',
seed = 90291,
burn = 10000,
iter = 10000)
mymodel@output
# FCS Imputation for Random Intercept Regression
library(fdir)
library(rblimp)
library(rockchalk)
library(lme4)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
problemsolving2level <- read.table('problemsolving2level.dat', na.strings = '999')
names(problemsolving2level) <- c('school','student','condition','teachexp','eslpct','hispanic','male','frlunch',
'lowach','stanmath','efficacypre','efficacypst','psolvepre','psolvepst')
##################################################
# fit model with mcmc (ex16.1.imp)
##################################################
mymodel <- rblimp(
data = problemsolving2level,
clusterid = 'school',
ordinal = 'condition hispanic frlunch',
fixed = 'condition psolvepre',
center = 'groupmean = psolvepre hispanic frlunch; grandmean = psolvepre.mean hispanic.mean frlunch.mean',
model = 'psolvepst ~ psolvepre hispanic frlunch psolvepre.mean hispanic.mean frlunch.mean condition',
seed = 90291,
burn = 5000,
iter = 10000)
mymodel@output
# MCMC Two-Level Moderated Regression With Random Slopes
library(fdir)
library(rblimp)
library(rockchalk)
library(lme4)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
problemsolving3level <- read.table('problemsolving3level.dat', na.strings = '999')
names(problemsolving3level) <- c('school','student','wave','condition','teachexp','eslpct','hispanic',
'male','frlunch','lowach','stanmath','month', 'month7', 'probsolve', 'efficacy')
##################################################
# fit model with mcmc (ex17.1.imp)
##################################################
mymodel <- rblimp(
data = problemsolving3level,
clusterid = 'student',
ordinal = 'hispanic frlunch condition',
fixed = 'month condition',
center = 'grandmean = frlunch',
model = '
probsolve ~ month hispanic frlunch condition month*condition month*hispanic | month',
simple = 'month | condition; month | hispanic',
seed = 90291,
burn = 10000,
iter = 20000)
mymodel@output
# MCMC Three-Level Moderated Regression With Random Slopes
library(fdir)
library(rblimp)
library(rockchalk)
library(lme4)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
problemsolving3level <- read.table('problemsolving3level.dat', na.strings = '999')
names(problemsolving3level) <- c('school','student','wave','condition','teachexp','eslpct','hispanic',
'male','frlunch','lowach','stanmath','month', 'month7', 'probsolve', 'efficacy')
##################################################
# fit model with mcmc (ex18.1.imp)
##################################################
mymodel <- rblimp(
data = problemsolving3level,
clusterid = 'school student',
ordinal = 'male frlunch condition',
fixed = 'month7 male condition',
center = 'grandmean = male frlunch teachexp',
model = '
probsolve ~ month7 male frlunch teachexp condition month7*condition | month7',
simple = 'month7 | condition',
seed = 90291,
burn = 20000,
iter = 50000)
mymodel@output
# MCMC Linear Regression
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
behaviorachievement <- read.table('behaviorachievement.dat', na.strings = 999)
names(behaviorachievement) <- c('id','male','hispanic','riskgrp','atrisk','behsymp1','lrnprob1',
'read1','read2','read3','read9','read9grp','stanread7',
'math1','math2','math3','math9','math9grp','stanmath7')
##################################################
# fit model with mcmc (ex19.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
transform = 'm = ismissing(read9)',
ordinal = 'm',
model = '
focal.model:
read9 ~ read1 lrnprob1 behsymp1;
missingness.model:
m ~ read9 lrnprob1;
auxiliary.model:
stanread7 read2  ~ read9 read1 lrnprob1 behsymp1',
seed = 90291,
burn = 1000,
iter = 10000)
mymodel@output
# MCMC Linear Regression
library(fdir)
library(rblimp)
library(mitml)
##################################################
# read data
##################################################
# set working directory
set()
# read imputed data from working directory
behaviorachievement <- read.table('behaviorachievement.dat', na.strings = 999)
names(behaviorachievement) <- c('id','male','hispanic','riskgrp','atrisk','behsymp1','lrnprob1',
'read1','read2','read3','read9','read9grp','stanread7',
'math1','math2','math3','math9','math9grp','stanmath7')
##################################################
# fit model with mcmc (ex20.imp)
##################################################
mymodel <- rblimp(
data = behaviorachievement,
transform = 'm = 1 - ismissing(read9)',
ordinal = 'm',
model = '
focal.model:
read9 ~ 1@beta0com m@beta0diff read1 lrnprob1 behsymp1;
missingness.model:
m ~ 1@missmean;
predictor.model:
read1 lrnprob1 behsymp1 ~ m;
auxiliary.model:
stanread7 read2  ~ read9 m read1 lrnprob1 behsymp1',
parameters = 'cohensd = -.20;
beta0diff = cohensd * sqrt(read9.totalvar);
pmis = phi(missmean);
pcom = 1 - pmis;
beta0 = (beta0com * pcom) + ((beta0com + beta0diff) * pmis)',
seed = 90291,
burn = 1000,
iter = 10000)
mymodel@output
